﻿<?php App::import('I8000'); ?>
<h3>Thông tin giỏ hàng của bạn</h3>
<?php if(empty($orders)) { ?>
	<div class="box s4 empty-cart">
		<?php echo __('Basket is empty', true); ?>
	</div>
<?php } else { ?>
	<?php echo $form->create(array('action'=>'index')); ?>
	<div class="basket">
		<table width="100%" class="list" border="1" bordercolor="#80cde7" style="border-collapse: collapse;">
			<thead>
				<th width="80px" align="center"><?php echo __('Mã hàng', true); ?></th>
				<th><?php echo __('Product name', true); ?></th>
				<th width="110px" align="center"><?php echo __('Số lượng', true); ?></th>
				<th width="110px" align="right"><?php echo __('Đơn giá', true); ?></th>
				<th width="110px" align="right"><?php echo __('Thành tiền', true); ?></th>
			</thead>

			<tbody>
				<?php foreach($orders as $item) { ?>
				<tr>
					<td align="center">
						<?php echo $item['id']; ?>
					</td>

					<td>
						<?php echo $item['name']; ?>
					</td>

					<td align="center">
						<?php echo $form->input(
							'quantity',
							array(
								'type'		=> 'text',
								'value'		=> $item['quantity'],
								'onchange'	=> 'update_value(' . $item['id'] . ', this.value);',
								'label'		=> false,
								'div'		=> false,
								'size'		=> 20
							)
						); ?>
					</td>

					<td align="right">
						<span class="price">
							<?php echo I8000::nice_money($item['cost']); ?>
						</span>
					<td align="right">
						<span class="price">
							<?php echo I8000::nice_money($item['cost'] * $item['quantity']); ?>
						</span>
					</td>
				<tr>
				<?php } ?>
			</tbody>
		</table>
	</div>

	<div class="submit">
		<?php
		echo $html->link(
			__('Continue', true),
			array(
				'controller'	=> 'payment',
				'action'		=> 'step_one'
			),
			array(
				'id'			=> 'continue',
				'class'			=> 'h30x137 checkout'
			)
		);
		?>

	</div>
	<script type="text/javascript">
		function update_value(id, value) {
			var status = $("#status");
			status.html('<?php echo $html->image('loading.gif') . __('Number of products purchased is being updated.', true); ?>');
			status.css('display', 'block');
			$.ajax({
				url: '<?php echo Router::url(array('controller'=>'basket', 'action'=>'update')); ?>',
				type: 'POST',
				data: {'id':id, 'value':value},
				success: function(data){
					//console.log(data);
					status.html(data);
				}
			});
		}
	</script>
<?php } ?>